/** I N C L U D E S **************************************************/
#include <p18f46k22.h>
#include "Gyrometre.h"
#include "transmission.h"

#include <delays.h>

/** C O N F I G U R A T I O N   B I T S ******************************/

#pragma config FOSC = HSHP //HS oscillator (high power > 16 MHz)
#pragma config WDTEN = OFF, LVP = OFF, MCLRE = EXTMCLR //Watchdog timer off, single-supply ICSP disabled, MCLR pin enabled

/** I N T E R U P T I O N S ******************************************/

void InterruptHandlerHigh (void);

#pragma code _vecteur_it_high = 0x08
    void InterruptVectorHigh(void){
	  _asm
		goto InterruptHandlerHigh //jump to interrupt routine
	  _endasm
	}
#pragma code 

unsigned char X;
unsigned char Y;
unsigned char Z;

#pragma interrupt InterruptHandlerHigh

	void InterruptHandlerHigh (){
		
		/** G E S T I O N   I N T 0   **********************************************************/
		if (INTCONbits.INT0IF){						//check for Int0 interupt
			int X1;
			int Y1;
			int Z1;	
			allumerLed(100);	
			if(axeChoix==0) X=recupererMot()-X0;
			if(axeChoix==1) Y=recupererMot()-Y0;
			if(axeChoix==2) Z=recupererMot()-Z0;
			X1 = (int)X * 0.070 / 94.8 * 3;
			Y1 = (int)Y * 0.070 / 94.8 * 3;
			Z1 = (int)Z * 0.070 / 94.8 * 3;
			allumerLed(101);
			envoyerDonnees(convertirDonnees(X1,Y1,Z1),17);
			allumerLed(110);			
			INTCONbits.INT0IF = 0;					//reset Int0Flag_Int
		}
	}

	void main (void){
		int i =0;
		initGyro();
		initTransmission();
		allumerLed(010);
		while (i==0){
			allumerLed(011);
			testGyro();
			i++;
		}
	}